package com.example.administrator.shuqiangjian.cn.hnevc.shuqiangjian;

/**
 * Created by Administrator on 2021/1/2.
 */
import android.content.Context;
import android.content.res.AssetManager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class JsonParse {
    public String JsonParse(Context context, String filename) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assetManager.open(filename)));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuilder.toString();
    }
    public List<qiuduiInfo> getInfosFromJson(Context context){
        List<qiuduiInfo> qiuduiInfos = new ArrayList<>();
        InputStream is = null;
        try {
            is = context.getResources().getAssets().open("qiudui.json");
            String  json = line(is);
            Gson gson = new Gson();
            Type listTyoe = new TypeToken<List<qiuduiInfo>>(){}.getType();
            List<qiuduiInfo> infoList = gson.fromJson(json,listTyoe);
            return infoList;
        }catch (Exception e){

        }

        return qiuduiInfos;
    }
}
